﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Web.Security;

namespace Utility
{
    public class PasswordManage
    {
        /// <summary>
        /// Strong generate password with MD5 encoding.
        /// </summary>
        /// <param name="rawText">give a string</param>
        /// <returns>string after encode</returns>
        public static string GeneratePasswordMD5(string rawText)
        {
            System.Text.Encoding encoding = System.Text.Encoding.ASCII;
            rawText += "vnshYucOng";

            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] bRes = md5.ComputeHash(encoding.GetBytes(rawText));
            string stRes = Convert.ToBase64String(bRes);
            md5.Clear();
            return stRes;
        }
        
        /// <summary>
        /// Encode password with MD5 format
        /// </summary>
        /// <param name="strPassword">the password need to encode</param>
        /// <returns>password encoded</returns>
        public static string EncodePassword(string strPassword)
        {
            return FormsAuthentication.HashPasswordForStoringInConfigFile(strPassword + "LibSecurity", "MD5");
        }
    }
}
